package util;
/**
 * Simple Clock
 * 
 * This simple clock is supposed to provide a means to keep track of time.  The timer will
 * track how long it has run for.
 * 
 * @version 1.0
 * @author Alexander Schearer <aas11@duke.edu>
 * @author Jimin Choi
 */
public class SimpleClock {
	
	private double myStartTime;
	private double myElapsedTime;
	
	public SimpleClock()
	{
		reset();
	}
	/**
	 * Start the clock
	 *
	 * The clock will now record time.
	 */
	public void start()
	{
		myStartTime = getCurrentTime();
	}
	/**
	 * Stop the clock
	 * 
	 * Set the start time back to zero and track how long the timer has been running.
	 *
	 */
	public void stop()
	{
		softReset();
	}
	/**
	 * Retrieve how long the clock has been running but do not stop the clock
	 * 
	 * @return
	 */
	public double elapsedTime()
	{
		softReset();
		myStartTime = getCurrentTime();
		return myElapsedTime;
	}
	/**
	 * Reset the clock so that it's elapsed time is set to zero
	 *
	 */
	public void reset()
	{
		myStartTime = 0;
		myElapsedTime = 0;
	}
	/**
	 * Reset the clock so just it's start time is set ot zero but its elapsed time is updated
	 *
	 */
	private void softReset()
	{
		myElapsedTime += getRuntime();
		myStartTime = 0;
	}
	/**
	 * Retrieve how long the clock has been running
	 * 
	 * @return
	 */
	private double getRuntime()
	{
		return System.currentTimeMillis() - myStartTime;
	}
	/**
	 * Retrieve the current time from the system
	 * 
	 * @return
	 */
	private double getCurrentTime()
	{
		return System.currentTimeMillis();
	}

}
